﻿using System.IO;
using System.IO.Compression;
using Framework.Core.Recorder;
using Xunit;

namespace Framework.Tests.Core.Recorder.AcceptanceTests
{
    public class StateFullTest
    {
        [Fact]
        public void Should_record_parameters_modified_by_implementation_with_state_full_context()
        {
            var recorder = new StateFullHardMock().BuildRecorderOver<_MUODate>(new MUODate());

            var param = "pouet";

            recorder.Control(ref param);

            var file = Path.GetTempFileName();

            using (var stream = File.Open(file, FileMode.Create, FileAccess.Write))
            {
                using (var zipStream = new GZipStream(stream, CompressionMode.Compress))
                {
                    recorder.Snapshot(zipStream);
                }
            }

            Assert.Equal("toto", param);

            var param2 = "pouet";

            using (var stream = File.OpenRead(file))
            {
                using (var zipStream = new GZipStream(stream, CompressionMode.Decompress))
                {
                    var replayer = new StateFullHardMock().BuildMockFrom<_MUODate>(zipStream);

                    replayer.Control(ref param2);
                    Assert.Equal("toto", param2);
                }
            }

            if (File.Exists(file))
            {
                File.Delete(file);
            }
        }
    }
}
